#include "header.h"

pthread_t serverThread;															// Server thread for server running on given node
pthread_t dispatcherThread;
pthread_t msgLifeTimerThread;
pthread_t keepAliveThread;
pthread_t autoShutdownThread;
pthread_t commandLineThread;
pthread_t checkThread;

int iretServerThread; 
int iretConnectThread;
int iretReadThread;
int iretWriteThread;
int iretChildThread;
int iretDispatcherThread;
int iretMsgLifeTimerThread;
int iretKeepAliveThread;
int iretAutoShutdownThread;


bool shutdownFlag = false;
int resetFlag = 0;																	// set if node is reset (if it has never been started before)
char *startupFile = NULL;															// startup.ini
bool IsBeaconNode = false;
bool resetKeepAlive[512] = {false};
bool deleteConnection[512] = {false};													// flag will to set by read thread to notify write thread of duplicate connection and will delete the thread
bool joinToTheNetworkFlag = true;											//set true as for first time it needs to get into while loop of JOINTOTHENETWORK function
bool ctrlFlag = false;
bool checkFlag;
bool checkActive = false;

struct timeval statusFirst, statusLast;

string checkUOID;

pthread_mutex_t NeighborList = PTHREAD_MUTEX_INITIALIZER;
pthread_mutex_t ReadQueue = PTHREAD_MUTEX_INITIALIZER;
pthread_mutex_t WriteQueue[512] = {PTHREAD_MUTEX_INITIALIZER};
pthread_mutex_t UoidMap = PTHREAD_MUTEX_INITIALIZER;
pthread_mutex_t ResetKeepAlive[512] = {PTHREAD_MUTEX_INITIALIZER};
pthread_mutex_t deleteConnectionLock[512] = {PTHREAD_MUTEX_INITIALIZER};


pthread_cond_t  condition_var_Read = PTHREAD_COND_INITIALIZER;
pthread_cond_t  condition_var_Write[512] = {PTHREAD_COND_INITIALIZER};



list<Messages> writeQueue[512];											// write queue different for all write threads
list<Messages> readQueue;													// read queue common for all read threads


uint16_t connectBeaconPort;

map<string,int> checkUoidSockDesc;


StartUpConfigurationFile node;
fileConfig fileObject;
char bitvectorBuffer[256];  // to calculate the bit vector
